Fix failing tests
authorjluner <justin.j.luner@gmail.com>
Sat, 27 May 2017 07:21:48 +0000 (02:21 -0500)
committerjluner <justin.j.luner@gmail.com>
Sat, 27 May 2017 07:21:48 +0000 (02:21 -0500)
src/bin/cargo.rs
src/cargo/lib.rs
src/cargo/ops/cargo_rustc/custom_build.rs
src/cargo/sources/git/source.rs
src/cargo/sources/git/utils.rs
src/cargo/util/errors.rs
src/cargo/util/process_builder.rs
tests/cargotest/support/mod.rs

index 4c838a632907453c75c695e06422d386145f2f99..cbb8c48c8efde75296805117ce00ec151f3cd46c 100644 (file)
@@ -84,7 +84,9 @@ fn main() {
     let result = (|| {
         let args: Vec<_> = try!(env::args_os()
             .map(|s| {
-                s.into_string().map_err(|s| CargoError::from(format!("invalid unicode in argument: {:?}", s)))
+                s.into_string().map_err(|s| {
+                    CargoError::from(format!("invalid unicode in argument: {:?}", s))
+                })
             })
             .collect());
         let rest = &args;
index 06eb8705af454f4de872f99aec0baef4fd52bd7a..a04836a46d18d9d31b31d7167dd1247f5dff2bb8 100755 (executable)
@@ -206,7 +206,8 @@ pub fn handle_error(err: CargoError, shell: &mut MultiShell) {
     handle_cause(err, shell);
 }
 
-fn handle_cause<E, EKind>(cargo_err: E, shell: &mut MultiShell) -> bool where E: ChainedError<ErrorKind=EKind> + 'static {
+fn handle_cause<E, EKind>(cargo_err: E, shell: &mut MultiShell) -> bool
+    where E: ChainedError<ErrorKind=EKind> + 'static {
     fn print(error: String, shell: &mut MultiShell) {
         let _ = shell.err().say("\nCaused by:", BLACK);
         let _ = shell.err().say(format!("  {}", error), BLACK);
@@ -237,7 +238,8 @@ fn handle_cause<E, EKind>(cargo_err: E, shell: &mut MultiShell) -> bool where E:
         //Print remaining errors until one marked as Internal appears
         for err in cargo_err.iter().skip(1) {
             let err = unsafe { extend_lifetime(err) };
-            if let Some(&CargoError(CargoErrorKind::Internal(..), ..)) = err.downcast_ref::<CargoError>() {
+            if let Some(&CargoError(CargoErrorKind::Internal(..), ..)) =
+                err.downcast_ref::<CargoError>() {
                 return false;
             }
 
index 12b87aa33534da80047471a02b4f8c4d2f0778ca..3e988865a2a7cb8833213e8cf269a06e16fc57fb 100644 (file)
@@ -239,9 +239,10 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
             &mut |out_line| { state.stdout(out_line); Ok(()) },
             &mut |err_line| { state.stderr(err_line); Ok(()) },
         ).map_err(|e| {
-            let desc = e.description().to_string();
-            CargoError::with_chain(e, format!("failed to run custom build command for `{}`\n{}",
-                             pkg_name, desc))
+            CargoError::from(
+                format!("failed to run custom build command for `{}`\n{}",
+                        pkg_name, e.description()))
+
         })?;
 
         paths::write(&output_file, &output.stdout)?;
index 326fa94f24716474216099b573754a2fa910b749..43a5605ee58af89b57760e1af33eb3796a76ecdc 100644 (file)
@@ -5,7 +5,8 @@ use url::Url;
 use core::source::{Source, SourceId};
 use core::GitReference;
 use core::{Package, PackageId, Summary, Registry, Dependency};
-use util::{CargoResult, Config};
+use util::Config;
+use util::errors::{CargoError, CargoResult};
 use util::hex::short_hash;
 use sources::PathSource;
 use sources::git::utils::{GitRemote, GitRevision};
@@ -147,7 +148,7 @@ impl<'cfg> Source for GitSource<'cfg> {
             trace!("updating git source `{:?}`", self.remote);
 
             let repo = self.remote.checkout(&db_path, self.config)?;
-            let rev = repo.rev_for(&self.reference)?;
+            let rev = repo.rev_for(&self.reference).map_err(CargoError::to_internal)?;
             (repo, rev)
         } else {
             (self.remote.db_at(&db_path)?, actual_rev.unwrap())
index 9052f7a14a800a15873fa9dc13123a1dee9a1399..35252e396b9316586484367ae57284603aad2cf0 100644 (file)
@@ -296,9 +296,11 @@ impl<'a> GitCheckout<'a> {
             info!("update submodules for: {:?}", repo.workdir().unwrap());
 
             for mut child in repo.submodules()?.into_iter() {
-                update_submodule(repo, &mut child, cargo_config).chain_err(|| {
-                    format!("failed to update submodule `{}`",
-                            child.name().unwrap_or(""))
+                update_submodule(repo, &mut child, cargo_config)
+                    .map_err(CargoError::to_internal)
+                    .chain_err(|| {
+                        format!("failed to update submodule `{}`",
+                                child.name().unwrap_or(""))
                 })?;
             }
             Ok(())
@@ -530,7 +532,7 @@ fn with_authentication<T, F>(url: &str, cfg: &git2::Config, mut f: F)
     // In the case of an authentication failure (where we tried something) then
     // we try to give a more helpful error message about precisely what we
     // tried.
-    res.chain_err(|| {
+    res.map_err(CargoError::from).map_err(|e| e.to_internal()).chain_err(|| {
         let mut msg = "failed to authenticate when downloading \
                        repository".to_string();
         if !ssh_agent_attempts.is_empty() {
index 718e9619fa846f6f81775c46118b212b3c3df635..ef5e5e4e918ec5472bc982eeb0758b8c63ecdef4 100644 (file)
@@ -62,6 +62,7 @@ error_chain! {
 
 impl CargoError {
     pub fn to_internal(self) -> Self {
+        //This is actually bad, because it loses the cause information for foreign_link
         CargoError(CargoErrorKind::Internal(self.description().to_string()), self.1)
     }
 
@@ -72,6 +73,7 @@ impl CargoError {
             &CargoErrorKind::TomlDe(_) => true,
             &CargoErrorKind::Curl(_) => true,
             &CargoErrorKind::HttpNot200(..) => true,
+            &CargoErrorKind::ProcessErrorKind(_) => true,
             &CargoErrorKind::CrateRegistry(_) |
             &CargoErrorKind::ParseSemver(_) |
             &CargoErrorKind::Semver(_) |
@@ -83,7 +85,6 @@ impl CargoError {
             &CargoErrorKind::Parse(_) |
             &CargoErrorKind::Git(_) |
             &CargoErrorKind::Internal(_) |
-            &CargoErrorKind::ProcessErrorKind(_) |
             &CargoErrorKind::CargoTestErrorKind(_) => false
         }
     }
index 4cb642b73397d4f7d7919b6976fb2e586c484eed..819771981eeb93efc4c6b17304903d5f55490bd5 100644 (file)
@@ -84,9 +84,9 @@ impl ProcessBuilder {
         if exit.success() {
             Ok(())
         } else {
-            Err(CargoErrorKind::ProcessErrorKind(process_error(&format!("process didn't exit successfully: `{}`",
-                                       self.debug_string()),
-                              Some(&exit), None)).into())
+            Err(CargoErrorKind::ProcessErrorKind(process_error(
+                &format!("process didn't exit successfully: `{}`", self.debug_string()),
+                Some(&exit), None)).into())
         }
     }
 
@@ -97,9 +97,8 @@ impl ProcessBuilder {
         let mut command = self.build_command();
         let error = command.exec();
         Err(CargoError::with_chain(error,
-            CargoErrorKind::ProcessErrorKind(
-                process_error(&format!("could not execute process `{}`",
-                self.debug_string()), None, None))))
+            CargoErrorKind::ProcessErrorKind(process_error(
+                &format!("could not execute process `{}`", self.debug_string()), None, None))))
     }
 
     #[cfg(windows)]
@@ -120,9 +119,9 @@ impl ProcessBuilder {
         if output.status.success() {
             Ok(output)
         } else {
-            Err(CargoErrorKind::ProcessErrorKind(process_error(&format!("process didn't exit successfully: `{}`",
-                                       self.debug_string()),
-                              Some(&output.status), Some(&output))).into())
+            Err(CargoErrorKind::ProcessErrorKind(process_error(
+                &format!("process didn't exit successfully: `{}`", self.debug_string()),
+                Some(&output.status), Some(&output))).into())
         }
     }
 
@@ -181,14 +180,14 @@ impl ProcessBuilder {
             status: status,
         };
         if !output.status.success() {
-            Err(CargoErrorKind::ProcessErrorKind(process_error(&format!("process didn't exit successfully: `{}`",
-                                       self.debug_string()),
-                              Some(&output.status), Some(&output))).into())
+            Err(CargoErrorKind::ProcessErrorKind(process_error(
+                &format!("process didn't exit successfully: `{}`", self.debug_string()),
+                Some(&output.status), Some(&output))).into())
         } else if let Some(e) = callback_error {
             Err(CargoError::with_chain(e,
-                CargoErrorKind::ProcessErrorKind(
-                    process_error(&format!("failed to parse process output: `{}`",
-                    self.debug_string()), Some(&output.status), Some(&output)))))
+                CargoErrorKind::ProcessErrorKind(process_error(
+                    &format!("failed to parse process output: `{}`", self.debug_string()),
+                    Some(&output.status), Some(&output)))))
         } else {
             Ok(output)
         }
index 3a4e556536645d8e6837897b48db573c0d1db7f6..8177785b25c1acb70c3201259acd7882785bb31f 100644 (file)
@@ -719,7 +719,8 @@ impl<'a> ham::Matcher<&'a mut ProcessBuilder> for Execs {
 
         match res {
             Ok(out) => self.match_output(&out),
-            Err(CargoError(CargoErrorKind::ProcessErrorKind(ProcessError { output: Some(ref out), .. }), ..)) => {
+            Err(CargoError(CargoErrorKind::ProcessErrorKind(
+                ProcessError { output: Some(ref out), .. }), ..)) => {
                 self.match_output(out)
             }
             Err(e) => {